package com.atguigu.spzx.manager.config;

import com.atguigu.spzx.manager.Interceptor.LoginAuthInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author LT
 * @create 2023-11-03-16:36
 */
@Configuration
public class SpzxManageerWebMvcConfigure implements WebMvcConfigurer {

    @Resource
    LoginAuthInterceptor loginAuthInterceptor;

    @Resource
    SpzxWhiteUrls spzxWhiteUrls;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginAuthInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(spzxWhiteUrls.getUrls());
    }
    //@CrossOrigin(originPatterns="*",allowedHeaders="*" , allowCredentials = "true" )
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("*")
                .allowCredentials(true);
    }
}
